/*
 * FilebyApp.java
 */
package fileby.main;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import fileby.ctrl.MouseGesturesHandler;
import fileby.model.IModel;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * The main class of the application.
 */
public class Main {

    private static Injector injector;
    @Inject
    private static IModel model;

    public static Injector getInjector() {
        return injector;
    }

    /**
     * At startup create and show the main frame of the application.
     */
    protected void startup() {
        model.init();
    }

    private static void setLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        setLookAndFeel();

        injector = Guice.createInjector(new FilebyModule());
        injector.getInstance(MouseGesturesHandler.class);
        // Forcing Initiation via Guice
        model = injector.getInstance(IModel.class);
        injector.getInstance(JFrame.class);
        injector.getInstance(Main.class).startup();
    }
}
